package com.stylefeng.guns.modular.platform.service.impl;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.common.constant.Enum.SellerAuditStatusEnum;
import com.stylefeng.guns.common.constant.Enum.SellerStatusEnum;
import com.stylefeng.guns.core.result.BaseResultVo;
import com.stylefeng.guns.core.result.JsonReturnHelper;
import com.stylefeng.guns.modular.platform.dao.SellerDemandMapper;
import com.stylefeng.guns.modular.platform.model.SellerDemand;
import com.stylefeng.guns.modular.platform.service.ISellerDemandService;

/**
 * <p>
 * 平台卖家需求 服务实现类
 * </p>
 *
 * @author stylefeng123
 * @since 2018-07-13
 */
@Service
public class SellerDemandServiceImpl extends ServiceImpl<SellerDemandMapper, SellerDemand> implements ISellerDemandService {
private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Override
	public BaseResultVo addSellerDemand(SellerDemand sellerDemand) {
		try{
			sellerDemand.setStatus(SellerStatusEnum.DJS.getValue());
			sellerDemand.setAuditStatus(SellerAuditStatusEnum.DSH.getValue());
			sellerDemand.setCreatedBy(String.valueOf(sellerDemand.getUserId()));
			sellerDemand.setGmtCreate(new Date());
			sellerDemand.setLastUpdatedBy(String.valueOf(sellerDemand.getUserId()));
			sellerDemand.setGmtLastUpdate(new Date());
			
			baseMapper.insert(sellerDemand);
		}catch(Exception e){
			logger.error(e.getMessage(), e);
			return JsonReturnHelper.getFailWithError("服务异常，请稍后重试", "5001");
		}
		return JsonReturnHelper.getSuccessWithNull();
	}

	@Override
	public BaseResultVo deleteSellerDemandById(Integer sellerDemandId) {
		try{
			baseMapper.deleteById(sellerDemandId);
		}catch(Exception e){
			logger.error(e.getMessage(), e);
			return JsonReturnHelper.getFailWithError("服务异常，请稍后重试", "5001");
		}
		return JsonReturnHelper.getSuccessWithNull();
	}

	@Override
	public BaseResultVo updateSellerDemandById(SellerDemand sellerDemand) {
		try{
			sellerDemand.setLastUpdatedBy(String.valueOf(sellerDemand.getUserId()));
			sellerDemand.setGmtLastUpdate(new Date());
			
			baseMapper.updateById(sellerDemand);
		}catch(Exception e){
			logger.error(e.getMessage(), e);
			return JsonReturnHelper.getFailWithError("服务异常，请稍后重试", "5001");
		}
		return JsonReturnHelper.getSuccessWithNull();
	}

	@Override
	public BaseResultVo selectSellerDemandById(Integer sellerDemandId) {
		SellerDemand sellerDemand = null;
		try{
			sellerDemand = baseMapper.selectById(sellerDemandId);
		}catch(Exception e){
			logger.error(e.getMessage(), e);
			return JsonReturnHelper.getFailWithError("服务异常，请稍后重试", "5001");
		}
		return JsonReturnHelper.getSuccessWithData(sellerDemand);
	}

	@Override
	public BaseResultVo selectSellerDemandList(EntityWrapper<SellerDemand> wp) {
		List<SellerDemand> list= null;
		try{
			list= baseMapper.selectList(wp);
		}catch(Exception e){
			logger.error(e.getMessage(), e);
			return JsonReturnHelper.getFailWithError("服务异常，请稍后重试", "5001");
		}
		return JsonReturnHelper.getSuccessWithData(list);
	}

	@Override
	public BaseResultVo selectSellerDemandPage(Page<SellerDemand> page, EntityWrapper<SellerDemand> wp) {
		Page<SellerDemand> pageList = null;
		try{
			pageList = page.setRecords(baseMapper.selectPage(page, wp));
		}catch(Exception e){
			return JsonReturnHelper.getFailWithError("服务异常，请稍后重试", "5001");
		}
		return JsonReturnHelper.getSuccessWithData(pageList);
	}

}
